
package com.mephi.model.profile;


import java.util.Vector;
import com.mephi.exception.NoSuchElementException;
import com.mephi.interfaces.Game;
import com.mephi.interfaces.GameList;
import com.mephi.model.Move;


/**
 * A Simple default implementation.
 * @author mephisto
 * 1.0 2011-05-26
 */
public class GameListImpl implements GameList
{
	public GameListImpl()
	{
		gameList = new Vector<Game<Move>>();
	}
	
	@Override
	public void add(Game<Move> game) throws IllegalArgumentException
	{
		if (game.getId() < 0)
			throw new IllegalArgumentException("Id of the game must be " +
					"greater than zero, but the given id is: " + game.getId());
		gameList.add(game);	
	}
	
	@Override
	public Game<Move> getGame(int id) throws NoSuchElementException, IllegalArgumentException
	{
		if (id < 0)
			throw new IllegalArgumentException("Id must be greater than zero, " +
					"but the given id is: " + id);
		
		Game<Move> game = null;
		for (Game<Move> it: gameList)
		{
			if (it.getId() == id)
				game = it;
		}
		if (game == null)
			throw new NoSuchElementException(Integer.toString(id));
		
		return game;
	}
	
	@Override
	public void remove(int id) throws NoSuchElementException, IllegalArgumentException
	{
		gameList.remove(getGame(id));
	}
	

	private Vector<Game<Move>> gameList;
}
